home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 2.iso / dist / fw_libgtop.idb / usr / freeware / doc / libgtop / netload.c.z / netload.c
C/C++ Source or Header  |  2002-07-08  |  4KB  |  126 lines

  1. /* $Id: netload.c,v 1.7.2.1 1999/09/16 21:08:55 martin Exp $ */
  2.  
  3. /* Copyright (C) 1998-99 Martin Baulig
  4.    This file is part of LibGTop 1.0.
  5.  
  6.    Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
  7.  
  8.    LibGTop is free software; you can redistribute it and/or modify it
  9.    under the terms of the GNU General Public License as published by
  10.    the Free Software Foundation; either version 2 of the License,
  11.    or (at your option) any later version.
  12.  
  13.    LibGTop is distributed in the hope that it will be useful, but WITHOUT
  14.    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15.    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  16.    for more details.
  17.  
  18.    You should have received a copy of the GNU General Public License
  19.    along with LibGTop; see the file COPYING. If not, write to the
  20.    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  21.    Boston, MA 02111-1307, USA.
  22. */
  23.  
  24. #include <locale.h>
  25.  
  26. #include <glibtop.h>
  27. #include <glibtop/open.h>
  28. #include <glibtop/close.h>
  29. #include <glibtop/xmalloc.h>
  30.  
  31. #include <glibtop/parameter.h>
  32.  
  33. #include <glibtop/netload.h>
  34.  
  35. #include <netinet/in.h>
  36. #include <arpa/inet.h>
  37.  
  38. #ifndef PROFILE_COUNT
  39. #define PROFILE_COUNT    1
  40. #endif
  41.  
  42. int
  43. main (int argc, char *argv [])
  44. {
  45.     glibtop_netload netload;
  46.     unsigned method, count, port;
  47.     struct in_addr addr, subnet;
  48.     char *address_string, *subnet_string;
  49.     char buffer [BUFSIZ];
  50.  
  51.     count = PROFILE_COUNT;
  52.  
  53.     setlocale (LC_ALL, "");
  54.     bindtextdomain (PACKAGE, GTOPLOCALEDIR);
  55.     textdomain (PACKAGE);
  56.     
  57.     glibtop_init_r (&glibtop_global_server, 0, GLIBTOP_INIT_NO_OPEN);
  58.  
  59.     glibtop_get_parameter (GLIBTOP_PARAM_METHOD, &method, sizeof (method));
  60.  
  61.     printf ("Method = %d\n", method);
  62.  
  63.     count = glibtop_get_parameter (GLIBTOP_PARAM_COMMAND, buffer, BUFSIZ);
  64.     buffer [count] = 0;
  65.  
  66.     printf ("Command = '%s'\n", buffer);
  67.  
  68.     count = glibtop_get_parameter (GLIBTOP_PARAM_HOST, buffer, BUFSIZ);
  69.     buffer [count] = 0;
  70.  
  71.     glibtop_get_parameter (GLIBTOP_PARAM_PORT, &port, sizeof (port));
  72.  
  73.     printf ("Host = '%s' - %u\n\n", buffer, port);
  74.  
  75.     glibtop_init_r (&glibtop_global_server, 0, 0);
  76.  
  77.     if (argc != 2)
  78.         glibtop_error ("Usage: %s interface", argv [0]);
  79.     
  80.     glibtop_get_netload (&netload, argv [1]);
  81.  
  82.     addr.s_addr = netload.address;
  83.     subnet.s_addr = netload.subnet;
  84.  
  85.     address_string = glibtop_strdup (inet_ntoa (addr));
  86.     subnet_string  = glibtop_strdup (inet_ntoa (subnet));
  87.  
  88.     printf ("Network Load (0x%08lx):\n\n"
  89.         "\tInterface Flags:\t0x%08lx\n"
  90.         "\tAddress:\t\t0x%08lx - %s\n"
  91.         "\tSubnet:\t\t\t0x%08lx - %s\n\n"
  92.         "\tMTU:\t\t\t%ld\n"
  93.         "\tCollisions:\t\t%ld\n\n"
  94.         "\tPackets In:\t\t%ld\n"
  95.         "\tPackets Out:\t\t%ld\n"
  96.         "\tPackets Total:\t\t%ld\n\n"
  97.         "\tBytes In:\t\t%ld\n"
  98.         "\tBytes Out:\t\t%ld\n"
  99.         "\tBytes Total:\t\t%ld\n\n"
  100.         "\tErrors In:\t\t%ld\n"
  101.         "\tErrors Out:\t\t%ld\n"
  102.         "\tErrors Total:\t\t%ld\n\n",
  103.         (unsigned long) netload.flags,
  104.         (unsigned long) netload.if_flags,
  105.         (unsigned long) netload.address, address_string,
  106.         (unsigned long) netload.subnet,  subnet_string,
  107.         (unsigned long) netload.mtu,
  108.         (unsigned long) netload.collisions,
  109.         (unsigned long) netload.packets_in,
  110.         (unsigned long) netload.packets_out,
  111.         (unsigned long) netload.packets_total,
  112.         (unsigned long) netload.bytes_in,
  113.         (unsigned long) netload.bytes_out,
  114.         (unsigned long) netload.bytes_total,
  115.         (unsigned long) netload.errors_in,
  116.         (unsigned long) netload.errors_out,
  117.         (unsigned long) netload.errors_total);
  118.  
  119.     glibtop_free (address_string);
  120.     glibtop_free (subnet_string);
  121.  
  122.     glibtop_close ();
  123.  
  124.     exit (0);
  125. }
  126.